package com.tobestronger.shouxiespringframework.context.event;


import com.tobestronger.shouxiespringframework.beans.factory.BeanFactory;
import com.tobestronger.shouxiespringframework.context.ApplicationEvent;
import com.tobestronger.shouxiespringframework.context.ApplicationListener;

import java.util.Collection;

/**
 * 简单事件广播器实现
 */
public class SimpleApplicationEventMulticaster extends AbstractApplicationEventMulticaster {

    public SimpleApplicationEventMulticaster(BeanFactory beanFactory) {
        setBeanFactory(beanFactory);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void multicastEvent(final ApplicationEvent event) {
        Collection<ApplicationListener> listeners = getApplicationListeners(event);
        for (final ApplicationListener listener : listeners) {
            listener.onApplicationEvent(event);
        }
    }

}
